home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4490 / 4490.xpi / components / scripts / hotmail.js < prev    next >
Text File  |  2010-01-28  |  4KB  |  128 lines

  1. /***********************************************************
  2. Live(Hotmail)
  3. ***********************************************************/
  4. var hostString="hotmail.com";
  5. var supportInboxOnly=true;
  6. var supportShowFolders=true;
  7.  
  8. function init(){
  9.   this.initStage=ST_PRE;
  10.   this.loginData=["","login","passwd"];
  11.   this.dataURL="http://mail.live.com/?rru=inbox";
  12.   this.mailURL="http://mail.live.com/?rru=inbox";
  13.   this.mailDomain="mail.live.com";
  14.   if(this.password.length>16)this.password=this.password.substring(0,16);
  15. }
  16. function getIconURL(){
  17.   return "http://login.live.com/favicon.ico";
  18. }
  19. function process(aHttpChannel, aData) {
  20.   switch(this.stage){
  21.   case ST_PRE:
  22.     this.getHtml("http://mail.live.com/mail/logout.aspx");
  23.     return false;
  24.   case ST_PRE_RES:
  25.     this.getHtml("http://mail.live.com");
  26.     return false;
  27.   case (ST_PRE_RES+1):
  28.     var fnd=aData.match(/srf_uPost=\'([\s\S]+?)\'/);
  29.     if(fnd){
  30.       this.loginData[LOGIN_URL]=fnd[1];
  31.       fnd=aData.match(/PPFT[\s\S]+?value=\"(\S+?)\"/);
  32.       if(fnd){
  33.         this.stage=ST_LOGIN;
  34.         this.getHtml(this.loginData[LOGIN_URL],this.loginData[LOGIN_POST]+"&PPFT="+encodeURIComponent(fnd[1]));
  35.         return false;
  36.       }
  37.     }
  38.     this.onError();
  39.     return true;
  40.   case ST_LOGIN_RES:
  41.     var fnd=aData.match(/<form.+?action="(.+?)"/);
  42.     if(fnd){//@msn.com
  43.       var fnd0=aData.match(/<input.+?name=[\'\"](\S+?)[\'\"].+?value=[\'\"](\S+?)[\'\"]/);
  44.       var post;
  45.       if(fnd0){
  46.         post=fnd0[1]+"="+encodeURIComponent(fnd0[2]);
  47.       }
  48.       this.getHtml(fnd[1],post);
  49.       return false;
  50.     }else{
  51.       fnd=aData.match(/replace\([\'\"](\S+?)[\'\"]/);
  52.       if(fnd){
  53.         this.getHtml(fnd[1]);
  54.         return false;
  55.       }
  56.       this.onError();
  57.       return true;
  58.     }
  59.   case (ST_LOGIN_RES+1):
  60.     this.getHtml(this.mailURL);
  61.     return false;
  62.   case (ST_LOGIN_RES+2):
  63.     var fnd=aData.match(/id=\"UIFrame\".+?src=\"(\S+)\"/);
  64.     if(fnd){
  65.       fnd=fnd[1].replace(/&#(\d+);/g,function(){return String.fromCharCode(RegExp.$1);});
  66.       this.dataURL=fnd;
  67.       var url=this.dataURL.match(/(((\S+):\/\/([^/]+))(\S*\/)?)([^/]*)/);
  68.       if(url)this.mailHost=url[2];
  69.       this.stage=ST_DATA;
  70.       break;
  71.     }
  72.     this.onError();
  73.     return true;
  74.   }
  75.   return this.baseProcess(aHttpChannel, aData);
  76. }
  77. function getCount(aData){
  78.   return this.mailCount;
  79. }
  80. function getData(aData){
  81.   var obj={};
  82.   var ar=[];
  83.   this.folders={};//used for direct link  
  84.   var fnd0=aData.match(/<ul.+?folderList.+?>([\s\S]+?)<\/ul>/);
  85.   if(fnd0){
  86.     var fnd=fnd0[1].match(/<li\s+fid=\"fid\"[\s\S]+?>.+?<\/li>/g);
  87.     if(fnd){
  88.       var s;
  89.       var num=0;
  90.       for each(s in fnd){
  91.         s=s.match(/\s+id=\"(.+?([^-]+?))\".+?count=\"(\d+)\".+?title=\"(.+?)\"/);
  92.         if(s){
  93.           if(s[2]=="000000000005"||s[2]=="000000000004"
  94.             ||s[2]=="000000000003"||s[2]=="000000000002")continue;
  95.           var n=parseInt(s[3]);
  96.           if(this.inboxOnly){
  97.             if(s[2]=="000000000001")num=n;
  98.           }else num+=n;
  99.           if(n>0&&s[2]!="000000000001"){
  100.             var name=s[4];
  101.             name=name.replace(/&#(\d+);/g,function(){return String.fromCharCode(RegExp.$1);});
  102.             var f=name.match(/(.+?)\s\(\d+\)/);
  103.             if(f)name=f[1];
  104.             this.folders[name]=s[1];            
  105.             ar.push(name);
  106.             ar.push(n);
  107.           }
  108.         }
  109.       }
  110.       this.mailCount=num;
  111.       if(this.showFolders){
  112.         if(ar)obj.folders=encodeArray(ar);
  113.       }
  114.       return obj;
  115.     }
  116.   }
  117.   this.mailCount=-1;
  118.   return obj;
  119. }
  120. function getMailURL(aFolder){
  121.   if(aFolder&&this.mailHost){
  122.     var url=this.mailHost+"/mail/InboxLight.aspx?FolderID="+this.folders[aFolder]
  123.               +"&n="+parseInt(Math.random()*1000000000);
  124.     return url;
  125.   }
  126.   return this.mailURL;  
  127. }
  128.